package com.stone.framework.core.util;

import org.springframework.data.domain.Pageable;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

public final class Pages {

    public static <T> Page<T> convert(Pageable pageable, String orderBy) {
        Page<T> page = new Page<T>(pageable.getPageNumber(), pageable.getPageSize());
        return page.addOrder(
            pageable.getSort().getOrderFor(orderBy).isAscending() ? OrderItem.asc(orderBy) : OrderItem.desc(orderBy));
    }

}
